﻿DataProvider = function() 
{    
}
DataProvider.createDelegate = function(instance, method) {
	return function() {
		return method.apply(instance, arguments);
	}
}
DataProvider.prototype =
{ 
    _requestPage : function(url, isAsync, handler)
    {    
        this.request = null;
        this.isAsync = isAsync;
        this.handler = handler;		
		if (window.XMLHttpRequest)
			this.request = new window.XMLHttpRequest();
		else if (window.ActiveXObject)
			this.request = new window.ActiveXObject("Microsoft.XMLHTTP");
		else
			throw new Error("No XMLHttp Support");
		
		this.doc = null;
		 
        this.request.onreadystatechange =  DataProvider.createDelegate(this, this.handleReadyStateChange)//this.handleReadyStateChange;
		this.request.open("GET", url, isAsync);
		this.request.send(null);	
		if (!isAsync)
		    return this.doc;
    }, 
    
    handleReadyStateChange : function()
		{
			if (this.request.readyState == 4) 
			{
				if (this.request.status == 200)
				{
				    if (this.isAsync)
				    {
				        this.ResponseText =  this.request.responseText;
				        this.handler();
				     }   
					else
					{
					    return this.doc= this.request.responseText;					
					}
				}
				else
				{
					throw new Error("XML parsing failed: " + request.statusText);
				}
			}
		},
			 
    
    requestPage : function(url)
    {
        return this._requestPage(url,false,null);
    } ,
    requestAsyncPage : function(url,handler)
    {
        this._requestPage(url,true, handler);
    }  
}